package org.example.aienglishapp.service.progress;

import org.example.aienglishapp.entity.progress.DailyGoal;
import org.example.aienglishapp.mapper.progress.DailyGoalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class DailyGoalService {

    @Autowired
    private DailyGoalMapper dailyGoalMapper;

    // 获取指定用户的目标
    public List<DailyGoal> getGoalsByUserId(Long userId) {
        return dailyGoalMapper.findGoalsByUserId(userId);
    }

    // 添加新目标
    public DailyGoal addGoal(DailyGoal dailyGoal) {
        dailyGoal.setCompletedMinutes(0); // 初始化已完成时间
        dailyGoalMapper.addGoal(dailyGoal);
        return dailyGoal; // 返回带生成 ID 的目标
    }

    // 更新目标
    public DailyGoal updateGoal(Long id, DailyGoal updatedGoal) {
        updatedGoal.setId(id); // 设置目标 ID
        dailyGoalMapper.updateGoal(updatedGoal);
        return updatedGoal;
    }

    // 删除目标
    public void deleteGoal(Long id) {
        dailyGoalMapper.deleteGoal(id);
    }
}